import { removeCookies } from "@/service/cookieFun";

const user = {
  state: {
    // 用户数据
    userInfo: {
      name: "张三"
    },
    // 测试
    test: "测试"
  },
  mutations: {
    SET_USER_INFO: (state, userInfo) => {
      state.userInfo = userInfo;
    },
  },
  actions: {
    // 获取用户信息
    GetUserInfo({ commit }) {
      return new Promise((resolve, reject) => {
        console.log("获取用户信息userInfo");
        // getUserInfo()
        //   .then((res) => {
        //     commit("SET_USER_INFO", res.data);
        //     resolve(res);
        //   })
        //   .catch((error) => {
        //     reject(error);
        //   });
      });
    },
    // 退出登录
    LogOut({ commit }) {
      commit("SET_USER_INFO", {});
      removeCookies();
      location.href = "/";
    },
    // 测试
    Test({ commit }) {
      commit("SET_USER_INFO", { name: "测试" });
      console.log("正在调用store中的Test方法");
    }
  },
};

export default user;
